<?php
namespace EasyVote\EasyVoteBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\Persistence\ObjectManager;
use EasyVote\EasyVoteBundle\Entity\Role;
use EasyVote\EasyVoteBundle\Entity\RoleTree;

/**
 * Class LoadRoleData
 * Loads role information in the database
 * @package EasyVote\EasyVoteBundle\DataFixtures\ORM
 */
class LoadRoleData extends AbstractFixture implements OrderedFixtureInterface
{
    /**
     * {@inheritDoc}
     */
    public function load(ObjectManager $manager)
    {
        $id = 0;

        $userRole = new Role();
        $userRole->setValue('ROLE_USER');
        $userRole->setName('User');

        $userRole->setId(++$id);

        $manager->persist($userRole);
        $manager->flush();

        $adminRole = new Role();
        $adminRole->setValue('ROLE_ADMIN');
        $adminRole->setName('Administrator');

        $adminRole->setId(++$id);
        $adminRole->setChildNodeOf($userRole);

        $manager->persist($adminRole);
        $manager->flush();

        $monitorRole = new Role();
        $monitorRole->setValue('ROLE_MONITOR');
        $monitorRole->setName('Election Monitor');


        $monitorRole->setId(++$id);
        $monitorRole->setChildNodeOf($userRole);

        $manager->persist($monitorRole);
        $manager->flush();
    }

    /**
     * {@inheritDoc}
     */
    public function getOrder()
    {
        return 1; // the order in which fixtures will be loaded
    }
}

?>
